package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.center.acitivty.JyHfXqDbActivity;
import com.approval.approvalapp.center.bean.JyhfListBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/5/10.
 */

public class JyhfDbAdapter extends RecyclerView.Adapter<
        JyhfDbAdapter.Holder> {

    private List<JyhfListBean> jyhfListBeans;
    Context context;

    public void setJyhfListBeans(List<JyhfListBean> jyhfListBeans) {
        this.jyhfListBeans = jyhfListBeans;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_jyhf, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
            holder.tv1.setText(jyhfListBeans.get(position).getWJTITLE());
            holder.tv3.setText("建议人: " + jyhfListBeans.get(position).getWJNAME());
            holder.tv4.setText("建议单位: " + jyhfListBeans.get(position).getORGNAME());
            holder.tv5.setText("建议单位: " + jyhfListBeans.get(position).getWJTIME());

            holder.root.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.putExtra("id" , jyhfListBeans.get(position).getWJID());
                    intent.putExtra("state" , "待办");
                    intent.putExtra("title" , jyhfListBeans.get(position).getWJTITLE());
                    intent.setClass(context, JyHfXqDbActivity.class);
                    context.startActivity(intent);

                }
            });
    }

    @Override
    public int getItemCount() {
        if (jyhfListBeans == null){
        return 0;
        }else {
            return jyhfListBeans.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.tv5)
        TextView tv5;
//        @Bind(R.id.iv)
//        ImageView iv;
        @Bind(R.id.root)
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
